package com.hb.trade.server.project.section.service.status;

import com.hb.core.pojo.enums.SectionStatusEnum;
import com.hb.core.pojo.project.file.entity.BidFileInfo;
import com.hb.trade.server.project.file.service.BidFileInfoService;
import com.hb.core.pojo.project.section.dto.BidSectionDTO;
import lombok.Getter;
import lombok.Setter;
import org.fzzn.core.model.enums.LogicEnum;
import org.fzzn.core.util.Enums;
import org.springframework.stereotype.Service;

/**
 * 文件已发售
 *
 * @author zhaojk
 */
@Setter
@Getter
@Service
public class BidFileSold implements CalSectionStatus {

    /**
     * 当前逻辑的标段状态
     */
    private final static SectionStatusEnum SECTION_STATUS = SectionStatusEnum.BID_FILE_SOLD;

    protected final BidFileInfoService fileInfoService;

    /**
     * 排序号
     */
    private Integer sortCode = SECTION_STATUS.getCode();

    public BidFileSold(BidFileInfoService fileInfoService) {
        this.fileInfoService = fileInfoService;
    }

    @Override
    public Long getSectionStatus(BidSectionDTO section) {
        if (section == null) {
            return null;
        }
        Long fileId = section.getFileId();
        if (fileId == null) {
            return null;
        }
        BidFileInfo bidFileInfo = fileInfoService.getById(fileId);
        if (bidFileInfo == null) {
            return null;
        }
        Integer releaseFlag = bidFileInfo.getReleaseFlag();
        if (Enums.equals(LogicEnum.YES, releaseFlag)) {
            return SECTION_STATUS.getId();
        }
        return null;
    }

    @Override
    public Integer getSort() {
        return sortCode;
    }
}
